/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.vraptor.jpessoal.DAO;


import br.com.caelum.vraptor.ioc.Component;
import br.com.vraptor.jpessoal.bean.Sistema;
import br.com.vraptor.jpessoal.util.HibernateUtil;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;


@Component
public class SistemaDao {
    
     public List<Sistema> listar(){
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Query query = session.createQuery("from Sistema");
        List<Sistema> lista = query.list();
        session.getTransaction().commit();
                
        return lista;        
    }
     
     public Sistema obterPorId(Integer id) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Query query = session.createQuery("from Sistema where id = :id ");
        query.setParameter("id", id);
        Sistema sistema = (Sistema) query.uniqueResult();
        session.getTransaction().commit();
                
        return sistema;
    }
    
}
